package com.alks.function.service.impl.biocontrol.webwork;

import com.alks.common.data.thread.UserIdThread;
import com.alks.function.data.dto.biocontrol.webwork.DelDetDto;
import com.alks.function.data.dto.biocontrol.webwork.DeliveryListDto;
import com.alks.function.mapper.chengKong.PcLotHeadMapper;
import com.alks.function.service.biocontrol.webwork.IOrderDeliveryService;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import java.time.LocalDate;
import java.time.LocalDateTime;
import java.util.List;

/**
 * @author MS
 * @since 2025/3/21上午11:05
 */
@Service
@Slf4j
@RequiredArgsConstructor
public class OrderDeliveryServiceImpl implements IOrderDeliveryService {
    private final PcLotHeadMapper lotHeadMapper;

    @Override
    public List<DeliveryListDto> list(String date) {
        String companyId = UserIdThread.get().getCompanyId();
        LocalDateTime startDate = LocalDateTime.of(LocalDateTime.now().getYear(), 1, 1, 0, 0);
        LocalDateTime endDate = LocalDateTime.of(LocalDateTime.now().getYear() + 1, 1, 1, 0, 0);
        int dateFlag = 0;
        switch (date.length()){
            case 4:
                /*处理年度情况数据*/
                startDate = LocalDateTime.of(Integer.parseInt(date),1,1,0,0);
                endDate = LocalDateTime.of(Integer.parseInt(date),1,1,0,0).plusYears(1);
                break;
            case 6:
                /*处理月度细节数据情况*/
                startDate = LocalDateTime.of(Integer.parseInt(date.substring(0,4)),Integer.parseInt(date.substring(4,6)),1,0,0);
                endDate = LocalDateTime.of(Integer.parseInt(date.substring(0,4)),Integer.parseInt(date.substring(4,6)),1,0,0).plusMonths(1);
                dateFlag = 1;
                break;
            default:
                break;
        }
        return lotHeadMapper.getOrdDlvList(dateFlag,startDate,endDate,companyId);
    }

    @Override
    public List<DelDetDto> detailList(LocalDate startDate, Integer type) {
        String companyId = UserIdThread.get().getCompanyId();
        LocalDate endDate = LocalDate.now().plusMonths(1);
        /*获取细节数据*/
        return lotHeadMapper.getDelDetailList(startDate,endDate,type,companyId);
    }
}
